﻿

namespace QD.Cache
{
    /// <summary>
    /// 系统缓存工具类
    /// </summary>
    public class CacheUtil
    {
        /// <summary>
        /// 获取指定路径的缓存对象
        /// </summary>
        /// <param name="xPath"></param>
        /// <returns></returns>
        public static T Get<T>(string xPath)
        {
            T t = default(T);
            CacheHelp.TryGetValue<T>(xPath, out t);
            return t;
        }

       /// <summary>
       /// 添加一个缓存
       /// </summary>
       /// <typeparam name="T">缓存类型</typeparam>
       /// <param name="xPath">缓存路径</param>
       /// <param name="value">缓存值</param>
        public static void Add<T>(string xPath, T value)
        {
            CacheHelp.Set<T>(xPath, value, CacheTime.Default);
        }

        /// <summary>
        /// 添加一个缓存
        /// </summary>
        /// <typeparam name="T">缓存类型</typeparam>
        /// <param name="xPath">缓存路径</param>
        /// <param name="value">缓存值</param>
        /// <param name="timeOut">过期时间，单位：分钟</param>
        public static void Add<T>(string xPath, T value, int timeOut)
        {
            CacheHelp.Set<T>(xPath, value, timeOut);
        }
        /// <summary>
        /// 移除指定路径缓存
        /// </summary>
        /// <param name="xPath">路径</param>
        public static void Remove(string xPath)
        {
            CacheHelp.Remove(xPath);
        }
    }
}
